<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', array( 'before'=>'auth',function()
{
	if(Auth::user()->user_type_fk == Config::get("globals.adminTypePk"))
	{
		return Redirect::to('users');
	}
	else
	{
		return Redirect::to('requests');
	}
	
}));

Route::get('login', array('before'=>'authWhenLogin', 'uses'=>'UsersController@login'));

Route::post('login', 'UsersController@doLogin');

Route::get('dashboard', function(){
	return "En el dashbfffoard";
});

Route::get('home', function(){
	return View::make('pages.home');
});

Route::get('passwordRecovery', array('before'=>'isUserWithPasswordChanged','uses'=>'UsersController@showChangePassword'));
Route::post('passwordRecovery', array('before'=>'isUserWithPasswordChanged','uses'=>'UsersController@changePassword')); 

Route::group(array('before' => 'auth'), function(){
	//Users
	Route::get('users', 'UsersController@showUsers');
	Route::post('users/getUserInfo', 'UsersController@getUserInfo');
	Route::post('users/getUserEdit', 'UsersController@getUserEdit');
	Route::post('users/saveUser', 'UsersController@saveUser');
	Route::post('users/createUser', 'UsersController@getUserCreate');
	Route::post('users/deleteUser', 'UsersController@deleteUser');
	Route::post('users/restoreUser', 'UsersController@restoreUser');
	
	Route::post('users/regeneratePassword', 'UsersController@regeneratePassword');
	//Items
	Route::get('items', 'ItemsController@showItems');
	Route::post('items/getItemInfo', 'ItemsController@getItemInfo');
	Route::post('items/getItemEdit', 'ItemsController@getItemEdit');
	Route::post('items/saveItem', 'ItemsController@saveItem');
	Route::post('items/savePic', 'ItemsController@savePicture');
	Route::post('items/createItem', 'ItemsController@getItemCreate');
	Route::post('items/deleteItem', 'ItemsController@deleteItem');
	Route::post('items/restoreItem', 'ItemsController@restoreItem');

	Route::get('locations', 'ItemLocationsController@showLocations');
	Route::post('locations/getLocationInfo', 'ItemLocationsController@getLocationInfo');
	Route::post('locations/getLocationEdit', 'ItemLocationsController@getLocationEdit');
	Route::post('locations/saveLocation', 'ItemLocationsController@saveLocation');
	Route::post('locations/createLocation', 'ItemLocationsController@getLocationCreate');
	Route::post('locations/deleteLocation', 'ItemLocationsController@deleteLocation');
	Route::post('locations/getLocationItems', 'ItemLocationsController@getLocationItems');
	

	//Route::get('items/renameAllImages', 'ItemsController@renameAllImages');

	//Requests
	Route::get('requests', 'ItemRequestsController@showRequests');
	Route::post('requests/createRequest', 'ItemRequestsController@getRequestCreate');
	Route::post('requests/saveRequest', 'ItemRequestsController@saveRequest');
	Route::post('requests/showItems', 'ItemRequestsController@showItems');
	Route::post('requests/searchItems', 'ItemRequestsController@searchItems');
	Route::post('requests/resolveRequest', 'ItemRequestsController@resolveRequest');
	Route::post('requests/requestNewItem', 'ItemRequestsController@requestNewItem');
	Route::post('requests/sendNewItemRequest', 'ItemRequestsController@sendNewItemRequest');
});


Route::get('logout', 'UsersController@doLogout');
Route::get('fun', 'UsersController@fun');
//Test
//Route::get('test', 'ItemsController@test');

/*Route::get('test2', function(){
	print_r(ItemRequestItemStatus::where('description', '=', 'pendiente')->firstOrFail()->pk);
});*/
/*Route::get('recoverAdmin', 'UsersController@recoverAdmin');*/
